/**
 * User: Anton Petrov
 * Date: 3/10/13
 * Time: 7:09 PM
 */
package com.antonpetrov.controller.factory
{
	import com.antonpetrov.model.word.BasicWord;
	import com.antonpetrov.util.TestUtil;

	import org.flexunit.asserts.assertEquals;

	import org.flexunit.asserts.assertTrue;

	import org.flexunit.internals.runners.statements.ExpectException;

	public class WordsFactoryTest
	{
		private var methodToTest:Function;
		private var input:Array;
		private var desiredResult:Array;
		private var result:Array;

		[Before]
		public function before():void
		{
			methodToTest = null;
			input = null;
			result = ["Some invalid unwanted result!"];
			desiredResult = null;
		}

		[Test(description="Basic test for creating words from strings.")]
		public function testBasicWordsCreationFromStrings():void
		{
			methodToTest = WordsFactory.createWordsFromArrayOfStrings;
			input = [
				"word1", "description1",
				"word2", "description2",
				"word with spaces", "description with spaces"];
			desiredResult = [
				new BasicWord("word1", "description1"),
				new BasicWord("word2", "description2"),
				new BasicWord("word with spaces", "description with spaces")
			];

			result = methodToTest(input);

			TestUtil.assertEqualArrays(desiredResult, result);
		}

		[Test(description="Verifies exception on an invalid input.")]
		public function testWithInvalidInputOnCreationFromStrings():void
		{
			methodToTest = WordsFactory.createWordsFromArrayOfStrings;

			var haveAllExceptionsFired:Boolean = true;
			input = [
				["foo", "b a r", "bass-odd-length?"],
				null,
				["", "word for this is 0-length"]
			];

			for each (var inputArray:Array in input)
			{
				try
				{
					methodToTest(inputArray);
					haveAllExceptionsFired = false;
				}
				catch(error:Error)
				{
				}
			}

			assertTrue(haveAllExceptionsFired);
		}
	}
}
